package com.example.androidbighomework.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.androidbighomework.DongtaiActivity;
import com.example.androidbighomework.MainActivity;
import com.example.androidbighomework.PersonInfoActivity;
import com.example.androidbighomework.R;


public class MessageFragment extends Fragment {
    private LinearLayout mLLPersonInof,ll_dongtai;//个人信息和动态的LinearLayout

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //根据xml布局文件来实例化相应的View
        View view=inflater.inflate(R.layout.activity_message_fragment, container, false);
        mLLPersonInof=view.findViewById(R.id.ll_person_info);
        ll_dongtai=view.findViewById(R.id.ll_dongtai);
        ll_dongtai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), DongtaiActivity.class);
                final Integer accountid= ((MainActivity)getActivity()).getAccountId();
                Log.i("wwwwwwwwww", String.valueOf(accountid));
                if(accountid!=null){
                    Bundle bundle=new Bundle();
                    bundle.putInt(String.valueOf(DongtaiActivity.ACCOUNTID),accountid);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
                else {
                    Toast.makeText(getContext(), "尚未登录,请先登录", Toast.LENGTH_SHORT).show();
                }
            }
        });
        //监听点击事件完成页面跳转
        mLLPersonInof.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Integer accountid= ((MainActivity)getActivity()).getAccountId();
                if(accountid!=null){
                    Intent intent=new Intent(getActivity(), PersonInfoActivity.class);
                    startActivity(intent);
                }else {
                    Toast.makeText(getContext(), "尚未登录,请先登录", Toast.LENGTH_SHORT).show();
                }

            }
        });

        return view;
    }


}